package com.leyou.item.service;

import com.leyou.item.mapper.SpecGroupMapper;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.pojo.SpecGroup;
import com.leyou.item.pojo.SpecParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: taft
 * @Date: 2018-10-13 11:01
 */
@Service
public class SpecGroupService {

    @Autowired
    private SpecGroupMapper specGroupMapper;

    @Autowired
    private SpecParamMapper specParamMapper;

    public List<SpecGroup> querySpecGroups(Long cid) {

        SpecGroup specGroup = new SpecGroup();

        specGroup.setCid(cid);
        return specGroupMapper.select(specGroup);
    }

    public List<SpecParam> querySpecParam(Long gid,Long cid,Boolean searching,Boolean generic) {

        SpecParam specParam = new SpecParam();

        specParam.setGroupId(gid);

        specParam.setCid(cid);

        specParam.setSearching(searching);

        specParam.setGeneric(generic);

        return specParamMapper.select(specParam);
    }

    //根据分类的id查询当前分类对应规格参数组以及组内的参数信息
    public List<SpecGroup> querySpecsByCid(Long cid) {

        List<SpecGroup> specGroups = querySpecGroups(cid);

        for (SpecGroup specGroup : specGroups) {
            List<SpecParam> specParams = querySpecParam(specGroup.getId(), cid, null, null);
            specGroup.setParams(specParams);
        }


        return specGroups;
    }
}
